package com.jingtai.shop.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.common.webfacade.IdBO;
import com.jingtai.core.entity.shop.Evaluation;
import com.jingtai.shop.common.template.ShopBaseController;
import com.jingtai.shop.service.user.EvaluationService;
import com.jingtai.shop.webfacade.bo.evaluation.PageEvaluationBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * @author GR
 */
@Api(tags = "商城-评价")
@RestController
@RequestMapping("/shop/evaluation")
@CrossOrigin(origins = "*")
public class EvaluationController extends ShopBaseController {

    @Resource
    private EvaluationService evaluationService;

    /**
     * 根据商户编码查询评价列表
     * 商品详情
     */
    @ApiOperation(value = "根据商户编码查询评价列表")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/pageEvaluation")
    public Map<String, Object> pageEvaluation(@RequestBody PageEvaluationBO bo) {
        bo.validate();
        Page<Evaluation> evaluationPage = evaluationService.pageEvaluation(bo.getGoodsCode(), bo.getPageNo(), bo.getPageSize());
        return returnResultMap(ResultMapInfo.GETSUCCESS,evaluationPage);
    }

    /**
     * 用户删除评价
     */
    @ApiOperation(value = "用户删除评价")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/removeEvaluation")
    public Map<String, Object> removeEvaluation(@RequestBody IdBO bo) {
        bo.validate();
        boolean removeStatus = evaluationService.removeEvaluation(bo.getId());
        return returnResultMap(removeStatus ? ResultMapInfo.OPERATE_SUCCESS : ResultMapInfo.OPERATE_FAIL);
    }

}
